package org.atlantis.grosbeak.cable;

import javax.servlet.http.HttpSession;

import org.atlantis.grosbeak.cable.meta.SessionAware;
import org.atlantis.grosbeak.castor.Castors;

class DefaultSessionAware implements SessionAware {

	private HttpSession session;

	public DefaultSessionAware(HttpSession session) {
		this.session = session;
	}

	public Object getAttr(String key) {
		return session.getAttribute(key);
	}

	public <T> T getAttr(Class<T> type, String key) {
		Object value = session.getAttribute(key);
		T result = Castors.me().castTo(value, type);
		return result;
	}

	public HttpSession getSelf() {
		return session;
	}

	public void setAttr(String key, Object value) {
		session.setAttribute(key, value);
	}
}
